package com.example.myapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.app.ListActivity;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;

import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.List;

public class RateListActivity extends ListActivity {
    private Handler handler;
    private static final String TAG = "RateListActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        //准备数据
        String [] data={"one","two","three","four","five"};
        List<String> list1 = new ArrayList<String>();
        for(int i=1;i<100;i++){
            list1.add("item"+i);
        }

        //适配器
        ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,list1);
        setListAdapter(adapter);
        handler = new Handler(Looper.myLooper()){
            public void handleMessage(@NonNull Message msg){
                if(msg.what==7){

                    List<String> list2 = (List<String>) msg.obj;
                    ListAdapter adapter = new ArrayAdapter<String>(RateListActivity.this, android.R.layout.simple_list_item_1,list2);
                    setListAdapter(adapter);
                }
                super.handleMessage(msg);
            }
        };
        //开启线程获得数据
        MyThread listThread = new MyThread();
        listThread.setHandler(handler);
        Thread t = new Thread(listThread);
        t.start();

    }
}